home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Sound / LAME / WarpOS / src / dshow / Encoder.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-13  |  4.3 KB  |  159 lines

  1. /*
  2.  *    MPEG Audio Encoder for DirectShow
  3.  *    CEncoder definition
  4.  *
  5.  *    Copyright (c) 2000 Marie Orlova, Peter Gubanov, Elecard Ltd.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Library General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
  15.  * Library General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Library General Public
  18.  * License along with this library; if not, write to the
  19.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20.  * Boston, MA 02111-1307, USA.
  21.  */
  22.  
  23. #if !defined(AFX_VITECENCODER_H__40DC8A44_B937_11D2_A381_A2FD7C37FA15__INCLUDED_)
  24. #define AFX_VITECENCODER_H__40DC8A44_B937_11D2_A381_A2FD7C37FA15__INCLUDED_
  25.  
  26. #if _MSC_VER >= 1000
  27. #pragma once
  28. #endif // _MSC_VER >= 1000
  29.  
  30. #include "lame.h"
  31.  
  32. #define    INPUT_BUFF_SIZE        65536*2
  33. #define OUTPUT_BUFF_SIZE    16384
  34. #define    FRAME_SIZE_LAYER3    1152
  35.  
  36. extern DWORD dwBitRateValue[2][14];
  37.  
  38.  
  39. typedef struct {
  40.     DWORD    dwSampleRate;                    //SF in Hz
  41.     DWORD    dwBitrate;                        //BR in bit per second
  42.     vbr_mode    vmVariable;
  43.     DWORD    dwVariableMin;                  //specify a minimum allowed bitrate
  44.     DWORD    dwVariableMax;                  //specify a maximum allowed bitrate
  45.     DWORD    dwQuality;                      //Encoding quality
  46.     DWORD   dwVBRq;                         // VBR quality setting (0=highest quality, 9=lowest)                         
  47.     long    lLayer;                                    //Layer: 1 or 2
  48.  
  49.     DWORD    dwChMode;                                //Channel coding mode: see doc
  50.     DWORD    dwForceMS;
  51.  
  52.     DWORD    bCRCProtect;                        //Is CRC protection activated?
  53.     DWORD    bCopyright;                            //Is the stream protected by copyright?
  54.     DWORD    bOriginal;                          //Is the stream an original?
  55.  
  56.     DWORD    dwPES; 
  57.  
  58.     DWORD    dwEnforceVBRmin;
  59.     DWORD    dwVoiceMode; 
  60.     DWORD    dwKeepAllFreq; 
  61.     DWORD    dwStrictISO; 
  62.     DWORD    dwNoShortBlock; 
  63.     DWORD    dwXingTag; 
  64.     DWORD   dwModeFixed;
  65.     
  66. } MPEG_ENCODER_CONFIG;
  67.  
  68. ////////////////////////////////////////////////////////////////////////////////////////
  69. // CEncoder is a wraper class for VITEC audio encoder SDK
  70. ////////////////////////////////////////////////////////////////////////////////////////
  71. class CEncoder : public CCritSec
  72. {
  73. public:
  74.  
  75.     CEncoder();
  76.     virtual ~CEncoder();
  77.  
  78.     // Initialize encoder with PCM stream properties
  79.     HRESULT SetInputType(LPWAVEFORMATEX lpwfex);    // returns E_INVALIDARG if not supported
  80.     // GetInputType - returns current input type
  81.     HRESULT GetInputType(WAVEFORMATEX *pwfex)
  82.     { 
  83.         if(m_bInpuTypeSet)
  84.         {
  85.             memcpy(pwfex, &m_wfex, sizeof(WAVEFORMATEX));
  86.             return S_OK;
  87.         }
  88.         else
  89.             return E_UNEXPECTED;
  90.     }
  91.  
  92.     // Set MPEG audio parameters
  93.     HRESULT SetOutputType(MPEG_ENCODER_CONFIG &mabsi);        // returns E_INVALIDARG if not supported or
  94.                                                         // not compatible with input type
  95.     // Return current MPEG audio settings
  96.     HRESULT GetOutputType(MPEG_ENCODER_CONFIG* pmabsi)        
  97.     { 
  98.         if(m_bOutpuTypeSet)
  99.         {
  100.             memcpy(pmabsi, &m_mabsi, sizeof(MPEG_ENCODER_CONFIG));
  101.             return S_OK;
  102.         }
  103.         else
  104.             return E_UNEXPECTED;
  105.     }
  106.     
  107.     // Set if output stream is a PES
  108.     void SetPES(bool bPES)        
  109.     { 
  110.         m_mabsi.dwPES = bPES;
  111.     }
  112.     // Is output stream a PES
  113.     BOOL IsPES()        
  114.     { 
  115.         return (BOOL)m_mabsi.dwPES;
  116.     }
  117.     
  118.     // Initialize encoder SDK
  119.     HRESULT Init();
  120.     // Close encoder SDK
  121.     HRESULT Close();
  122.  
  123.     // Encode media sample data
  124.     HRESULT Encode(LPVOID pSrc, DWORD dwSrcSize, 
  125.                     LPVOID pDst, LPDWORD lpdwDstSize, REFERENCE_TIME rt);
  126.     HRESULT Finish(LPVOID pDst, LPDWORD lpdwDstSize);
  127.  
  128. protected:
  129.     
  130.     HRESULT SetDefaultOutputType(LPWAVEFORMATEX lpwfex); // 
  131.  
  132.     // Input meida type
  133.     WAVEFORMATEX   m_wfex;
  134.     // Output media type
  135.     MPEG_ENCODER_CONFIG m_mabsi;
  136.  
  137.     // Compressor private data
  138.     lame_global_flags *pgf;
  139.  
  140.     // Compressor miscelaneous state
  141.     BOOL    m_bInpuTypeSet;
  142.     BOOL    m_bOutpuTypeSet;
  143.  
  144.     // Refrence times of media samples
  145.     REFERENCE_TIME        m_rtLast;
  146.     BOOL                m_bLast;
  147.  
  148.     // PES headers routine
  149.     int            m_nPos;
  150.     int            m_nCounter;
  151.     LPBYTE        m_pPos;
  152.  
  153.     void        Reset();
  154.     void        CreatePESHdr(LPBYTE ppHdr, LONGLONG dwPTS, int dwPacketSize);
  155.     void        WriteBits(int nBits, int nVal);
  156. };
  157.  
  158. #endif // !defined(AFX_VITECENCODER_H__40DC8A44_B937_11D2_A381_A2FD7C37FA15__INCLUDED_)
  159.